import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [{
        path: '/',
        name: 'login',
        meta: {
            title: '鲤鱼科技 | 登录'
        },
        component: () =>
            import ('@/views/login/Login.vue')
    },
    {
        path: '/personal',
        name: 'personal',
        meta: {
            title: '鲤鱼科技 | 个人中心'
        },
        component: () =>
            import ('@/views/personal/Personal.vue'),
        children: [{
                path: "/personalData",
                name: "personalData",
                meta: {
                    title: '鲤鱼科技 | 个人中心 | 个人资料'
                },
                component: () =>
                    import ('@/views/personal/childrens/PersonalData.vue')
            },
            {
                path: "/collect",
                name: "collect",
                meta: { title: "鲤鱼科技 | 个人中心 | 我的收藏" },
                component: () =>
                    import ('@/views/personal/childrens/Collect.vue')
            },
            {
                path: "/integral",
                name: "integral",
                meta: { title: "鲤鱼科技 | 个人中心 | 我的积分" },
                component: () =>
                    import ('@/views/personal/childrens/Integral.vue')
            },
            {
                path: "/information",
                name: "information",
                meta: { title: "鲤鱼科技 | 个人中心 | 消息" },
                component: () =>
                    import ('@/views/personal/childrens/Information.vue')
            },
        ]
    },
    {
        path: '/H',
        component: () =>
            import ('@/views/Main.vue'),
        children: [{
                path: '/home',
                name: 'home',
                meta: {
                    title: '鲤鱼科技 | 首页'
                },
                component: () =>
                    import ('@/views/Home/Home.vue')
            },

            {
                path: '/web',
                name: 'web',
                meta: {
                    title: '鲤鱼科技 | 网站推荐'
                },
                component: () =>
                    import ('@/views/Web/Nav.vue')
            },
            {
                path: '/study_school',
                name: 'study_school',
                meta: {
                    title: '鲤鱼科技 | 在校学习'
                },
                component: () =>
                    import ('@/views/study_school/study_school.vue')
            },
            {
                path: '/study',
                name: 'study',
                meta: {
                    title: '鲤鱼科技 | 学习网站'
                },
                component: () =>
                    import ('@/views/Web/Study.vue')
            },
            {
                path: '/UI',
                name: 'ui',
                meta: {
                    title: '鲤鱼科技 | UI'
                },
                component: () =>
                    import ('@/views/Web/Ui.vue')
            },
            {
                path: '/Font',
                name: 'font',
                meta: {
                    title: '鲤鱼科技 | Font'
                },
                component: () =>
                    import ('@/views/Web/Font.vue')
            },

        ]
    },
    {
        path: "/we",
        name: "we",
        meta: { title: "鲤鱼科技 | 个人中心 | 联系我们" },
        component: () =>
            import ('@/views/we/We.vue'),
        children: [{
                path: "/contact",
                name: "contact",
                meta: { title: "鲤鱼科技 | 个人中心 | 联系我们" },
                component: () =>
                    import ('@/views/we/contact/Contact.vue')
            },

            {
                path: "/about",
                name: "About",
                meta: { title: "鲤鱼科技 | 个人中心 | 关于我们" },
                component: () =>
                    import ('@/views/we/About/About.vue')
            },
            {
                path: "/feedback",
                name: "feedback",
                meta: { title: "鲤鱼科技 | 个人中心 | 意见反馈" },
                component: () =>
                    import ('@/views/we/Feedback/Feedback.vue')
            },
        ]
    },

];


const router = new VueRouter({
    base: process.env.BASE_URL,
    routes,
});
router.beforeEach((to, from, next) => {

    let token = localStorage.getItem("token");
    if (token != null && from.path === "/") {
        next();
    } else if (token == null && to.name === "login") {
        next()
    } else if (token === "鲤鱼乡" && to.path === "/") {
        next("/home")
    } else if (token === null && to.path === "/home") {
        next("/");
    } else {
        next();
    }
});
export default router;